<style>
.el-table .cell {
    white-space: pre-line;
}
</style>
<template>
    <div>
        <page-header title="欢迎使用">
            <template #content>
                <div>
                    这是头部信息
                </div>
            </template>
        </page-header>
        <el-row :gutter="10" style="margin: 0 10px;" >
            <el-col :lg="24"> 
                <page-main title="" style="margin: 0 0 20px 0;">  
                   
                       
                    

                        <table-room ref="mychild"></table-room>
                      </page-main>          
            </el-col>
        </el-row>
    </div>
</template>

<script>
import msApi from "@/api/msApi";
import axios from 'axios';

  export default {
    name: "test",
    data() {
      return {    
        tableData: [], 
        loading:false,
         dialogFormVisible: false,
            ruleForm: {
                taskId: '',             
          },
            rules: {
                   taskId: [
                  { required: true, message: '请输入!', trigger: 'blur' },
                  { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                ], project: [
                  { required: true, message: '请输入!', trigger: 'blur' },
                  { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                ], room: [
                  { required: true, message: '请输入!', trigger: 'blur' },
                  { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                ]
        }
      }
    },
   		created() {
       },
    
    mounted() {
        // this.getResult();
        // this.loading = false;
 
    },
    methods:{

      
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      getState(){//获取当前状态
         this.$prompt('请输入任务Id', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(async({ value }) => {
              try {
              const res = await msApi.queryState(value)
              this.$message({
                showClose: true,
                dangerouslyUseHTMLString: true,
                message: '<strong>任务Id：</strong>'+res.data.data.taskId
                +'</br></br><strong>状态 ：</strong>'+res.data.data.state
                +'</br></br><strong>进度 ：</strong>'+res.data.data.progress+'%'
              });
            }catch (err) {
              console.log(err);
              this.$message.error('网络异常')
             }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
    },

      submitRules(){//上传测量标准
         this.$prompt('请输入任务Id', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(async({ value }) => {
              try {
              const res = await msApi.submitRules(value)
              this.$message.success("传入成功");
            }catch (err) {
              console.log(err);
              this.$message.error('网络异常')
             }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
    },

    async getResult(){//获取报表
           this.loading = true;
              try {
              const res = await msApi.getResult(514)
              // this.total = res.body.count;
              // this.currentPage = res.body.curr;
              var arr = new Array(3);
              // console.log(res.data);
              console.log(res.data.data);
              let _walls = res.data.data.walls;
              let wall_info = res.data.data.wall_info;
              let ewalls_p = '无',swalls_p = '无',wwalls_p = '无',nwalls_p = '无';
              let ewalls_c = '无',swalls_c = '无',wwalls_c = '无',nwalls_c = '无';
              let ceiling_s = '无',floor_p = '无';
              let bay_z = '无',bay_j = '无',depth_z = '无',depth_j = '无',heigth_z= '无',heigth_j = '无';
              let multiwalls_en = '无',multiwalls_wn = '无',multiwalls_es = '无',multiwalls_ws = '无'
              let height_design = 0,bay_design = 0,depth_design = 0
              // let eastWall,southWall,westWall,northWall;
              //仅考虑一个方向只有一堵墙的方正毛坯房的情况
              if(Object.keys(res.data.data.wall_info).length>4){
                this.$message.error('测量数据有问题，超过4堵墙了');
                return;
              }
              // Map(): 方向->墙号
              let wall_map = new Map();
              for(const i in wall_info){
                switch(wall_info[i]){
                  case 'E':
                    wall_map.set("E",i);
                    if(_walls[i]==undefined){
                      continue;
                    }
                    const eastWall = _walls[i].measurements;
                    for(const key in eastWall){
                      switch(eastWall[key].id){
                        case "2":
                          ewalls_p = eastWall[key].value;
                          break;
                        case "3":
                          ewalls_c = eastWall[key].value;
                          break;
                      }
                    }
                    break;
                  case 'S':
                    wall_map.set("S",i)
                    if(_walls[i]==undefined){
                      continue;
                    }
                    const southWall = _walls[i].measurements;
                    for(const key in southWall){
                      switch(southWall[key].id){
                        case "2":
                          swalls_p = this.__parseData(southWall[key].value);
                          break;
                        case "3":
                          swalls_c = this.__parseData(southWall[key].value);
                          break;
                      }
                    }
                    break;
                  case 'W':
                    wall_map.set("W",i);
                    if(_walls[i]==undefined){
                      continue;
                    }
                    const westWall = _walls[i].measurements;
                    for(const key in westWall){
                      switch(westWall[key].id){
                        case "2":
                          wwalls_p = westWall[key].value;
                          break;
                        case "3":
                          wwalls_c = westWall[key].value;
                          break;
                      }
                    }
                    break;
                  case 'N':
                    wall_map.set("N",i);
                    if(_walls[i]==undefined){
                      continue;
                    }
                    const northWall = _walls[i].measurements;break;
                    break;
                }
              }

              //处理天花板水平极差数据
              // console.log(res.data.data.room.measurements)
              const ceiling_info = res.data.data.ceiling.measurements;
              for(let i in ceiling_info){
                if(ceiling_info[i].id=="4"){
                  ceiling_s = ceiling_info[i].value;  //这是一个array
                  const _ceilingMax = Math.max(...ceiling_s);
                  const _ceilingMin = Math.min(...ceiling_s);
                  ceiling_s = _ceilingMax - _ceilingMin;
                }
              }
              //处理地板平整度数据
              const floor_info = res.data.data.floor.measurements;
              for(let i in floor_info){
                if(floor_info[i].id=="2"){
                  floor_p = this.__parseData(floor_info[i].value);
                }
              }
              //处理阴阳角数据
              const multiwalls_info = res.data.data.multiwalls;
              for(let key in multiwalls_info){
                let walls_arr = multiwalls_info[key].walls;
                let e_num = wall_map.get('E');
                let s_num = wall_map.get('S');
                let w_num = wall_map.get('W');
                let n_num = wall_map.get('N');
                console.log(wall_map.get('E'))
                console.log(walls_arr)
                console.log(walls_arr.includes(e_num))
                if( walls_arr.includes( e_num ) && walls_arr.includes( s_num ) ){
                  multiwalls_es = __parseData(multiwalls_info[key].value);
                }else if( walls_arr.includes( e_num ) && walls_arr.includes( n_num )){
                  multiwalls_en = __parseData(multiwalls_info[key].value);
                }else if( walls_arr.includes( w_num )&& walls_arr.includes( s_num )){
                  multiwalls_ws = __parseData(multiwalls_info[key].value);
                }else if( walls_arr.includes( w_num )&& walls_arr.includes( n_num )){
                  multiwalls_wn = __parseData(multiwalls_info[key].value);
                }
              }
              
              const room_info = res.data.data.room.measurements;
              for(let i in room_info){
                //id=21,净开间、净深最大值最小值
                if(room_info[i].id=="21"){
                  let bay_depth_arr = room_info[i].value;
                  //防止没测出数据，最大最小都为0的情况
                  if(bay_depth_arr[1]!=0 && bay_depth_arr[0]!=0){
                    //净开间极差
                    bay_j = bay_depth_arr[1]-bay_depth_arr[0];
                    // console.log(bay_j)
                  }
                  if(bay_depth_arr[3]!=0 && bay_depth_arr[2]!=0){
                    //净深极差
                    depth_j = bay_depth_arr[3]-bay_depth_arr[2];
                    // console.log(depth_j)
                  }
                }
                //id=8,净开间最大偏差
                if(room_info[i].id=="8"){
                  const bay_z_arr = room_info[i].value;
                  const bay_z_offset = Math.max(...bay_z_arr)-bay_design;
                  bay_z = bay_z_offset;
                }
                //id=8,净深最大偏差
                if(room_info[i].id=="9"){
                  const depth_z_arr = room_info[i].value;
                  const depth_z_offset = Math.max(...bay_z_arr)-depth_design;
                  depth_z = depth_z_offset;
                }
                //id=6,净高最大偏差
                if(room_info[i].id=="6"){
                  const heigth_arr = room_info[i].value;
                  // console.log("执行")
                  const height_z_offset = Math.max(...heigth_arr)-height_design;
                  heigth_z = height_z_offset;
                }
              }

              for(var i=0;i<3;i++){        
                  arr[i] = new Array(40);
                for(var j=0;j<40;j++){
                    
                    arr[i]['H'] = 1;
                    arr[i]['L1'] = 1; 
                    arr[i]['L2'] = 1
                    arr[i]['taskId'] = 1;
                    arr[i]['ewalls_p'] = ewalls_p;
                    arr[i]['ewalls_c'] = ewalls_c;
                    arr[i]['wwalls_p'] = wwalls_p;
                    arr[i]['wwalls_c'] = wwalls_c;
                    arr[i]['nwalls_p'] = nwalls_p;
                    arr[i]['nwalls_c'] = nwalls_c;
                    arr[i]['swalls_p'] = swalls_p;
                    arr[i]['swalls_c'] = swalls_c;
                    // arr[i]['ceiling_s'] = ceiling_s;
                    // arr[i]['floor_p'] = floor_p;
                    // arr[i]['heigth_z'] = heigth_z;
                    // arr[i]['heigth_j'] = heigth_j;
                    // arr[i]['bay_z'] = bay_z;
                    // arr[i]['bay_j'] = bay_j;
                    // arr[i]['depth_z'] = depth_z;
                    // arr[i]['depth_j'] = depth_j;
                    // arr[i]['multiwalls_en'] = multiwalls_en;
                    // arr[i]['multiwalls_wn'] = multiwalls_wn;
                    // arr[i]['multiwalls_es'] = multiwalls_es;
                    // arr[i]['multiwalls_ws'] = multiwalls_ws;
                    arr[i]['ceiling_s'] = 1;
                    arr[i]['floor_p'] = 1;
                    arr[i]['heigth_z'] = 1;
                    arr[i]['heigth_j'] = 1;
                    arr[i]['bay_z'] = 1;
                    arr[i]['bay_j'] = 1;
                    arr[i]['depth_z'] = 1;
                    arr[i]['depth_j'] = 1;
                    arr[i]['multiwalls_en'] = 1;
                    arr[i]['multiwalls_wn'] = 1;
                    arr[i]['multiwalls_es'] = 1;
                    arr[i]['multiwalls_ws'] = 1;
                }
            }    
              this.tableData = arr;
             

            }catch (err) {
              console.log(err);
              this.$message.error('网络异常')
             }
           this.loading = false;

          },
      __parseData(arrData){
        let str = '';
        for(let i in arrData){
          str = str + arrData[i] + '/';
        }
        return str = str.substring(0,str.lastIndexOf('/'));
      },
      __parseData2(arrData){
        let str = '';
        for(let i in arrData){
          str = str + arrData[i] + '\n';
        }
        return str = str.substring(0,str.lastIndexOf('\n'));
      },
        getWord(){//获取扫描模型        
            var tableToPrint = document.getElementById('tableId');//将要被打印的表格
            var newWin= window.open("");//新打开一个空窗口
            newWin.document.write(tableToPrint.outerHTML);//将表格添加进新的窗口
            newWin.document.close();//在IE浏览器中使用必须添加这一句
            newWin.focus();//在IE浏览器中使用必须添加这一句

            newWin.print();//打印
            newWin.close();//关闭窗口
        }, 

         testTable(){        
           this.$refs.mychild.title = 122
          
        }, 

        getModel(){//获取扫描模型
         this.$prompt('请输入任务Id', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
           window.open("http://10.7.5.131/#/h5/3dviewer?taskId="+value); 
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
      }, 
    }
  }
</script>